﻿@{
    ViewBag.Title = "AddMeter";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}

@using LeSoft.Application.Code;
<script>
    var _organizeid = request('OrganizeId');
    var BatchDate = request('BatchDate');
    var rowids = request('rowids');
    var _pstructId = "";
    $(function () {
        InitialPage();
        GetGrid();
    });
    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 165.5);
            }, 200);
            e.stopPropagation();
        });
    }

    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var lastsel;
        var $gridTable = $('#gridTable');
        var queryJson = {
            BatchDate: BatchDate,
            OrganizeId: _organizeid
        };
        $gridTable.jqGrid({
            url: "../../PropertyManage/CS_EnergyMeterReading/GetEneryMeterPageList",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            multiselect: true,
            mtype: "POST",
            height: $(window).height() - 165.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Id", hidden: true },
                { label: "EnergyMeterId", name: "EnergyMeterId", hidden: true },
                { label: "PStructId", name: "PStructId", hidden: true },
                { label: "表编号", name: "Code", index: "Code", width: 100, align: "center", sortable: false },
                { label: "表名称", name: "Name", index: "Name", width: 100, align: "center", sortable: false },
                { label: "所属房产", name: "AllName", index: "AllName", width: 200, align: "center", sortable: false },
                { label: "位置描述", name: "PSMemo", index: "PSMemo", width: 100, align: "center", sortable: false },
                {
                    label: "表种类", name: "Type", index: "Type", width: 100, align: "center", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        return cellvalue == null ? "" : top.clientdataItem["EnergyMeterType"][cellvalue];
                    }
                },
                {
                    label: "表性质", name: "Nature", index: "Nature", width: 100, align: "center", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        switch (cellvalue) {
                            case "1": return "单元表"; break;
                            case "2": return "公用表"; break;
                            case "3": return "虚拟表"; break;
                            default: return ""; break;
                        }
                    }
                },
                { label: "上次抄表时间", name: "ScaleDate", index: "ScaleDate", width: 100, align: "center", sortable: false },
                { label: "上次抄表期间", name: "BatchDate", index: "BatchDate", width: 100, align: "center", sortable: false },
                { label: "上次抄表读数", name: "ScaleNum", index: "Range", width: 100, align: "center", sortable: false },
                { label: "最高用量", name: "MaxVolume", index: "MaxVolume", width: 100, align: "center", sortable: false },
                { label: "最低用量", name: "MinVolume", index: "MinVolume", width: 100, align: "center", sortable: false },
                { label: "表容量", name: "Volume", index: "Volume", width: 100, align: "center", sortable: false },
                { label: "描述", name: "Description", index: "Description", width: 100, align: "center", sortable: false }
            ],
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortable: true,
            sortname: 'Code',
            sortorder: 'asc',
            rownumbers: true,
            onSelectRow: function (status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
                if (!!rowids) {
                    var rowIds = $gridTable.jqGrid('getDataIDs');
                    for (var k = 0; k < rowIds.length; k++) {
                        var data = $gridTable.getRowData(rowIds[k]);
                        if (rowids.indexOf(data.Id) > -1) {
                            $gridTable.jqGrid("delRowData", rowIds[k]);
                        }
                    }
                }
            }
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = {
                BatchDate: BatchDate,
                OrganizeId: _organizeid,
                condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
                keyword: $("#txt_Keyword").val()
            };
            $gridTable.jqGrid('setGridParam', {
                url: "../../PropertyManage/CS_EnergyMeterReading/GetEneryMeterPageList",
                postData: { queryJson: JSON.stringify(queryJson) }
            }).trigger('reloadGrid');
        });
    }

    function AcceptClick(callback) {
        var $gridTable = $('#gridTable');
        var obj = [];
        var ids = $gridTable.jqGrid('getGridParam', 'selarrrow');
        for (var i = 0; i < ids.length; i++) {
            var rowData = $gridTable.jqGrid('getRowData', ids[i]);
            obj.push(rowData);
        }
        callback(obj);
        dialogMsg("操作成功！", 1);
        dialogClose();
    }
</script>
<style>
    .center {
        text-align: center;
    }
</style>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr>
                            <td style="padding-left: 2px;">
                                <div class="btn-group" id="queryCondition">
                                    <a class="btn btn-default dropdown-text" data-toggle="dropdown">筛选条件</a>
                                    <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                                    <ul class="dropdown-menu">
                                        <li><a data-value="Code">编号</a></li>
                                        <li><a data-value="Name">名称</a></li>
                                    </ul>
                                </div>
                            </td>
                            <td style="padding-left: 2px;">
                                <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                            </td>
                            <td style="padding-left: 5px;">
                                <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
</div>
